


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ListProduit.java
 *
 * Created on 6 janv. 2009, 02:14:49
 */
package fr.miage.shopping.presentation.panel;

import fr.miage.shopping.metier.entite.Categorie;
import fr.miage.shopping.metier.entite.Produit;
import fr.miage.shopping.metier.impl.ProduitBusinessServiceImpl;
import java.util.List;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Vincents
 */
public class ListProduit extends JPanel {

    private DefaultTableModel model;

    public void chargement(Categorie categorie) {
        ProduitBusinessServiceImpl pb = new ProduitBusinessServiceImpl();
        List<Produit> list = pb.getProduitByCategorie(categorie);

        this.model.setNumRows(0);

        for (int i = 0; i < list.size(); i++) {
            Produit p = list.get(i);
            Vector rowData = new Vector();
            rowData.add(p.getNomProd());
            rowData.add(p.getDescription());
            rowData.add(p.getPrix());
            rowData.add(new Integer(p.getStockPhysique()));

            this.model.addRow(rowData);
            this.model.fireTableDataChanged();
        }

    }

    /** Creates new form ListProduit */
    public ListProduit() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jTable1.setRowSelectionAllowed(true);
        initComponents();

    }

    public Vector getSelectedRow() {
        int select = this.jTable1.getSelectedRow();
        Vector v = new Vector();
        if (select != -1) {
        v.add(this.model.getValueAt(select, 0));
        v.add("1");
        v.add(this.model.getValueAt(select, 2));
        v.add(this.model.getValueAt(select, 2));
        }
        return v;
    }

    private void initComponents() {


        //jTable1.setModel(null);
Object[] intitule = {
            "Apercu", "Description", "Prix", "Disponibilité"
        };
        this.model = new DefaultTableModel(intitule, intitule.length);
        this.model.setNumRows(0);
        jTable1.setModel(this.model);
        jScrollPane1.setViewportView(jTable1);
        //jTable1.getColumnModel().getColumn(0).setResizable(false);
        //jTable1.getColumnModel().getColumn(3).setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(14, Short.MAX_VALUE)));
    }// </editor-fold>
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration
}

